//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.chris.serve;

import com.alibaba.fastjson.JSON;
import com.chris.entity.content;
import com.chris.impl.contentImpl;
import com.chris.utils.DbConnection;
import com.chris.utils.JsonProcess;
import com.chris.utils.LogUtil;
import com.chris.utils.Page;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet({"/searchPaper"})
public class searchPaper extends HttpServlet {
    private final contentImpl dao = new contentImpl();

    public searchPaper() {
    }

    public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        PrintWriter writer = resp.getWriter();
        try {
            String paper_title = req.getParameter("paper_title");
            String author = req.getParameter("author");
            String Keyword = req.getParameter("Keyword");
            String currentPage = req.getParameter("currentPage");
            List<content>res=null;
            if (paper_title != null) {
                res = this.dao.search("paper_title", paper_title);
            } else if (author != null) {
                res = this.dao.search("author", author);
            } else if (Keyword !=null) {
                res = this.dao.search("Keyword", Keyword);
            }
            else {//三个都没选
                res  = dao.getAll();
            }
            if(res!=null){
                int total = res.size();
                Page page = new Page(currentPage,res);
                writer.print(JSON.toJSONString(JsonProcess.respSuccess("成功", page.pageNation(),total)));
            }
        } catch (Exception var8) {
            var8.printStackTrace();
            writer.print(JsonProcess.respError("参数错误"));
            LogUtil.log("参数错误",var8);
        }
        DbConnection.endServe();
    }
    public void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.addHeader("Access-Control-Allow-Headers", "*");
    }
}
